﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using QLTV_BLL;
using QLTV_Public;

namespace QLTV_GiaoDien
{
    public partial class frm_TaiLieu_NgonNgu_Them : DevExpress.XtraEditors.XtraForm
    {
        public frm_TaiLieu_NgonNgu_Them()
        {
            InitializeComponent();
        }
        private int _Flag;

        public int Flag
        {
            get { return _Flag; }
            set { _Flag = value; }
        }
        private int _MaNgonNgu;

        public int MaNgonNgu
        {
            get { return _MaNgonNgu; }
            set { _MaNgonNgu = value; }
        }
        private string _TenNgonNgu;

        public string TenNgonNgu
        {
            get { return _TenNgonNgu; }
            set { _TenNgonNgu = value; }
        }
        public delegate void GetInt(int kt);
        public GetInt MyGetData;
        public void GetData()
        {
            txt_MaNGonNgu.Text = MaNgonNgu.ToString();
            txt_TenNN.Text = TenNgonNgu;
        }
        public void LoadForm()
        {
            if (Flag == 0)
            {
                this.Text = "Thêm Mới Ngôn Ngữ";
                txt_MaNGonNgu.Enabled = false;
            }
            if (Flag == 1)
            {
                this.Text = "Sửa Ngôn Ngữ";
                txt_TenNN.ResetText();
                GetData();
            }
        }
        NgonNgu_BLL ngonNgu_bll = new NgonNgu_BLL();
        private void frm_TaiLieu_NgonNgu_Them_Load(object sender, EventArgs e)
        {
            LoadForm();
        }
        NhatKy_BLL nhatKy_bll = new NhatKy_BLL();
        NhatKy_Public nk = new NhatKy_Public();
        TrungGian tg = new TrungGian();
        private void btn_Luu_Click(object sender, EventArgs e)
        {
            NgonNgu_Public nn = new NgonNgu_Public();
            if (Flag == 0)
            {
                //them
                nn.TenNgonNgu = txt_TenNN.Text;
                ngonNgu_bll.insert_NgonNgu(nn);
                //
                string d = DateTime.Now.ToString();
                nk.MaNV = tg.MaNV;
                nk.NgayGio = d;
                nk.HanhDong = "Thêm";
                nk.MoTa = "Thêm mới Ngôn ngữ: '" + txt_TenNN.Text + "'";
                nhatKy_bll.insert_nhatKy(nk, nk, nk, nk);
                //
                XtraMessageBox.Show("Thêm mới thành công!","Thông Báo",MessageBoxButtons.OK,MessageBoxIcon.Information);
            }
            if (Flag == 1)
            {
                //sua
                nn.MaNgonNgu = int.Parse(txt_MaNGonNgu.Text);
                nn.TenNgonNgu = txt_TenNN.Text;
                ngonNgu_bll.Update_NgonNgu(nn,nn);
                //
                string d = DateTime.Now.ToString();
                nk.MaNV = tg.MaNV;
                nk.NgayGio = d;
                nk.HanhDong = "Sửa";
                nk.MoTa = "Sửa thông tin Ngôn Ngữ: '" + TenNgonNgu.ToString() + "' thành: '" +txt_TenNN.Text + "'";
                nhatKy_bll.insert_nhatKy(nk, nk, nk, nk);
                //
                XtraMessageBox.Show("Sửa thành công!", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            MyGetData(1);
            txt_MaNGonNgu.ResetText();
            txt_TenNN.ResetText();
        }

        private void btn_Huy_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void txt_MaNGonNgu_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!Char.IsDigit(e.KeyChar) && !Char.IsControl(e.KeyChar))
                e.Handled = true;
        }
    }
}